package com.bdqn.servlet.index;

import com.bdqn.pojo.SysUser;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * FrameServlet
 *
 * @author LILIBO
 * @since 2024/7/3
 */
@WebServlet("/frame")
public class FrameServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // 检查用户是否登录
        SysUser sysUser = (SysUser) request.getSession().getAttribute("userSession");
        if (sysUser == null) { // 用户未登录，跳转到登录页
            response.sendRedirect("login");
            return;
        }
        // 登录状态，跳转到主页
        request.getRequestDispatcher("jsp/frame.jsp").forward(request, response);
    }

}
